package com.example.zhulin.recyclerviewtest_219zl.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.zhulin.recyclerviewtest_219zl.R;
import com.example.zhulin.recyclerviewtest_219zl.adapter.MyAdapter;
import com.example.zhulin.recyclerviewtest_219zl.bean.ArticleBean;
import com.example.zhulin.recyclerviewtest_219zl.iface.ArticleListener;
import com.example.zhulin.recyclerviewtest_219zl.model.ArticleModel;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
       private RecyclerView recyclerView;
       private RecyclerView.LayoutManager layoutManager;
       private MyAdapter myAdapter;
    private  List<ArticleBean>list=null;

    ArticleListener articleListener=new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> beanList) {
                  list=beanList;
                  myAdapter.setList(list);
                  myAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this, "失败", Toast.LENGTH_SHORT).show();
        }
    };
       
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        initRecyclerView();

        ArticleModel model=new ArticleModel();
        model.getResultList("article",1,"rv1l2tidbomann2qn86nln6ur2",articleListener);
    }

    private void initRecyclerView() {
         recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);

        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
    }

    }

